﻿using System;
using System.Text;
using System.Xml.Serialization;
using System.Globalization;

namespace QuickDev.Licensing
{
    [Serializable]
    public class ProviderLicense : License , ILicense
    {
        #region Private Fields
        private string _domain;
        private DateTime _expirationDate;
        private string _key;
        private string _type;
        #endregion

        #region Public Properties

        /// <summary>
        /// Domain
        /// </summary>
        public override string Domain
        {
            get
            {
                return this._domain;
            }
            set
            {
                this._domain = value;
            }
        }

        /// <summary>
        /// ExpirationDate
        /// </summary>
        public override DateTime ExpirationDate
        {
            get
            {
                return this._expirationDate;
            }
            set
            {
                this._expirationDate = value;
            }
        }

        /// <summary>
        /// Key
        /// </summary>
        public override string Key
        {
            get
            {
                return this._key;
            }
            set
            {
                this._key = value;
            }
        }

        /// <summary>
        /// Signature
        /// </summary>
        [XmlIgnore]
        public override byte[] Signature
        {
            get
            {
                StringBuilder builder = new StringBuilder();
                builder.Append( this.Type );
                builder.Append( this.Domain );
                builder.Append( this.ExpirationDate.ToString( CultureInfo.CreateSpecificCulture( "en-US" ) ) );
                return Encoding.UTF8.GetBytes( builder.ToString() );
            }
        }

        /// <summary>
        /// Type
        /// </summary>
        public override string Type
        {
            get
            {
                return this._type;
            }
            set
            {
                this._type = value;
            }
        }

        #endregion
    }
}
